namespace TripleA.Core
{
    using System.Configuration;
    using System.Dynamic;

    /// <summary>
    /// DynamicObject wrapper around ConfigurationManager AppSettings - for use in your tests
    /// to easily access config properties.
    /// </summary>
    /// <remarks>http://stackoverflow.com/questions/4904480/how-can-i-use-a-dynamic-settings-blah-instead-of-appsettingsblah</remarks>
    public class AppSettings : DynamicObject
    {
        private static AppSettings _proxy;

        public static dynamic Current()
        {
            if (_proxy == null)
                _proxy = new AppSettings();
            return _proxy;
        }

        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            var setting = ConfigurationManager.AppSettings[binder.Name];
            if (setting != null)
            {
                result = setting;
                return true;
            }
            result = null;
            return false;
        }
    }
}